﻿using System;
using System.Web.Services;
using QuanLyHopDong.Biz;
using QuanLyHopDong.Web.Common;

namespace QuanLyHopDong.Web.DanhMuc.VatTu
{
    public partial class List : System.Web.UI.Page
    {
        private static VatTuBiz _vatTuBiz;
        private static VatTuBiz VatTuManager { get { return _vatTuBiz ?? (_vatTuBiz = new VatTuBiz()); } }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region web methods

        [WebMethod(EnableSession = true)]
        public static object VatTuList(int jtStartIndex, int jtPageSize, string jtSorting, string name)
        {
            int totalRecords;
            var results = VatTuManager.GetVatTus(jtStartIndex, jtPageSize, jtSorting, name, out totalRecords);

            return new { Result = "OK", Records = results, TotalRecordCount = totalRecords };
        }

        [WebMethod(EnableSession = true)]
        public static object Create(Biz.Model.VatTu record)
        {
            try
            {
                VatTuManager.CreateVatTu(record);
                return new { Result = "OK", Record = record };
            }
            catch (ApplicationException appEx)
            {
                return new { Result = "ERROR", Message = string.Format(WebCommon.GetGlobalString(appEx.Message), record.Name) };
            }
        }

        [WebMethod(EnableSession = true)]
        public static object Update(Biz.Model.VatTu record)
        {
            try
            {
                VatTuManager.UpdateVatTu(record);
                return new { Result = "OK" };
            }
            catch (ApplicationException appEx)
            {
                return new { Result = "ERROR", Message = string.Format(WebCommon.GetGlobalString(appEx.Message), record.Name) };
            }
        }

        #endregion
    }
}